using System;
using System.Collections.Generic;
using System.Text;
using Entities;
using DAL;
using Utility;

namespace BUS
{
    public class tbNhanVienBUS
    {
        public static void Insert(tbNhanVien nhanvien)
        {
            tbNhanVienDAL nvDAL = new tbNhanVienDAL();
            nvDAL.Insert(nhanvien);
        }
        public static void Update(tbNhanVien nhanvien)
        {
            tbNhanVienDAL nvDAl = new tbNhanVienDAL();
            nvDAl.Update(nhanvien);
        }
        public static void Delete(int iD)
        {
            tbNhanVienDAL nvDAl = new tbNhanVienDAL();
            nvDAl.Delete(iD);
        }
        public static tbNhanVienCollection Get(string where, int pageindex, int pagesize, string orderby, string orderdirection, out int total)
        {
            tbNhanVienDAL nvDAL = new tbNhanVienDAL();
            return nvDAL.Get(where, pageindex, pagesize, orderby, orderdirection, out total);
        }
        public static tbNhanVienCollection GetAll()
        {
            int total = 0;
            Criteria cri = new Criteria();
            tbNhanVienDAL nvDAL = new tbNhanVienDAL();
            return nvDAL.Get(cri.Criter, 0, 0, tbNhanVienColumns.MaNV.ToString(), OrderDirection.ASC.ToString(), out total);
        }
        public static tbNhanVien GetByID(int iD)
        {
            int total = 0;
            Criteria cri = new Criteria();
            cri.add(Condition.AND, tbNhanVienColumns.MaNV.ToString(), Condition.EQUAL, iD);
            tbNhanVienDAL nvDAL = new tbNhanVienDAL();
            tbNhanVienCollection nvCollection = nvDAL.Get(cri.Criter, 0, 0, tbNhanVienColumns.MaNV.ToString(), OrderDirection.ASC.ToString(), out total);
            if (nvCollection.Count > 0)
                return nvCollection[0];
            return null;
        }
        public static tbNhanVienCollection GetLimited(int number)
        {
            int total = 0;
            Criteria cri = new Criteria();
            tbNhanVienDAL nvDAL = new tbNhanVienDAL();
            return nvDAL.Get(cri.Criter, 1, number, tbNhanVienColumns.MaNV.ToString(), OrderDirection.DESC.ToString(), out total);
        }
        public static tbNhanVienCollection GetPromotion(int number)
        {
            int total = 0;
            Criteria cri = new Criteria();
            tbNhanVienDAL nvDAL = new tbNhanVienDAL();
            return nvDAL.Get(cri.Criter, 1, number, tbNhanVienColumns.MaNV.ToString(), OrderDirection.DESC.ToString(), out total);
        }
        public static Boolean KiemTraDangNhap(string user, string pass)
        {
            tbNhanVienDAL nvDAL = new tbNhanVienDAL();
            return nvDAL.KiemTraDangNhap(user, pass);
        }
        public static Boolean KiemTraNhanVien(string user)
        {
            tbNhanVienDAL nvDAL = new tbNhanVienDAL();
            return nvDAL.KiemTraNhanVien(user);
        }
        //public static tbNhanVien GetByTaiKhoan(string taikhoan)
        //{
        //    int total = 0;
        //    Criteria cri = new Criteria();
        //    cri.add(Condition.AND, tbNhanVienColumns.TaiKhoan.ToString(), Condition.EQUAL, taikhoan);
        //    tbNhanVienDAL nvDAL = new tbNhanVienDAL();
        //    tbNhanVienCollection nvCollection = nvDAL.Get(cri.Criter, 0, 0, tbNhanVienColumns.TaiKhoan.ToString(), OrderDirection.ASC.ToString(), out total);
        //    if (nvCollection.Count > 0)
        //        return nvCollection[0];
        //    return null;
        //}
    }
}
